import Events from "../Events";
import { hitRectangle } from '../util.js'


class ContentCache extends Events {
    constructor() {
        super();
        this.Content = {};
    }
    Create(type, x, y, zindex, options) {


        this.run('Delete', 'Create');
    }
    Each(callback) {
        for (const key in this.Content) {
            const element = this.Content[key];
            callback(element);
        }
    }
    CheckHit(Rectangle) {
        var _array = [];
        this.eachOptions((item) => {
            if (hitRectangle(Rectangle, item.getValue())) {
                _array.push(item);
            }
        })
        return _array;
    }
    EachOptions(callback) {
        for (const key in this.Content) {
            const element = this.Content[key];
            callback(element.getBaseOption());
        }
    }
    Delete(item) {
        item.destroy();
        this.run('Delete', item);
        delete this.Content[item.id];
    }
}

export default ContentCache;